Complete support for dynamic container names #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is my attempt to solve the same nginx-proxy#205 issue.
In Swarm Mode and Docker Cloud, container names are dynamic. nginx-proxy#181 solved this partially with a label on
jwilder/nginx-proxy
but not if they're separate containers. nginx-proxy#126 tries a different approach, but I think using a label is a better one.This PR simply adds a
com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen=true
label to the docker-gen container.It also moves the label related detection to runtime (functions.sh: nginx-reload) instead of startup time (entrypoint.sh), because the nginx and docker-gen containers could be redeployed during the lifecycle of the letsencrypt companion, and thus, getting different ids.
There's also a new assumption in that I think it's simpler to just recommend using the label instead of
volumes-from
to detect the nginx-proxy container. The reason is that in some environments (like mine), you can't usevolumes-from
, but I think you can always use labels.Note: If you're wandering why I've chosen not to set the variables
NGINX_DOCKER_GEN_CONTAINER
andNGINX_PROXY_CONTAINER
, that's because we can use them to make sure an explicitly set container name takes precedence over a label.Now I'm running a successful separate containers deployment in Swarm Mode, here's my stack:
As you can see, I'm also using a custom
helder/docker-gen
image which simply adds adocker-label-sighup
script that allows me to reload the nginx container from a label, because... well, dynamic names.jwilder/docker-gen
doesn't support reloading containers with dynamic names (yet).